#include<iostream>
#include<string>
using namespace std;
const int N = 1e5 + 10;
char s1[N], s2[N];
string getmin(char s[])
{
	int n = strlen(s + 1);
	for (int i = 1; i <= n; i++)s[i + n] = s[i];
	int i = 1, j = 2;
	while (j <= n) {
		int k = 0;
		while (k < n && s[i + k] == s[j + k])k++;
		if (s[i + k] > s[j + k])i += k + 1;
		else j += k + 1;
		if (i == j)j++;
		if (i > j)swap(i, j);
	}
	string ans;
	for (int l = i; l <= i + n - 1; l++)ans += s[l];
	return ans;
}
int main()
{
	scanf_s("%s%s", s1 + 1, s2 + 1);
	if (getmin(s1) == getmin(s2))cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}